
package com.jf.cloud.multishop.service.impl;

import com.jf.cloud.common.cache.constant.CacheNames;
import com.jf.cloud.common.cache.util.RedisUtil;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.util.PageUtil;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.multishop.mapper.ShopTemplateMapper;
import com.jf.cloud.multishop.model.ShopTemplate;
import com.jf.cloud.multishop.service.ShopTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 商品装修模板表
 *
 * @author zz
 * @date 2022-08-12 14:04:57
 */
@Service
public class ShopTemplateServiceImpl implements ShopTemplateService {

    @Autowired
    private ShopTemplateMapper shopTemplateMapper;

    @Override
    public PageVO<ShopTemplate> page(PageDTO pageDTO, ShopTemplate shopTemplate) {
        return PageUtil.doPage(pageDTO, () -> shopTemplateMapper.list(shopTemplate));
    }

    @Override
    @Cacheable(cacheNames = CacheNames.GET_BY_SHOP_TEMPLATE_ID_KEY, key = "#templateId")
    public ShopTemplate getByTemplateId(Long templateId) {
        return shopTemplateMapper.getByTemplateId(templateId);
    }

    @Override
    public void save(ShopTemplate shopTemplate) {
        shopTemplateMapper.save(shopTemplate);
    }

    @Override
    public void update(ShopTemplate shopTemplate) {
        shopTemplateMapper.update(shopTemplate);
    }

    @Override
    public void deleteById(Long templateId) {
        shopTemplateMapper.deleteById(templateId);
    }

    @Override
    public void removeCache(Long templateId) {
        RedisUtil.del(CacheNames.GET_BY_SHOP_TEMPLATE_ID_KEY + CacheNames.UNION + templateId);
    }
}
